package com.vint;

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Graphics;
import java.io.File;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class GameFrame extends JFrame{

	
	
	ArrayList<Boom> booms = new ArrayList<>();
	ArrayList<BasicPlane> emenies = new ArrayList<>();
	
	//建立线程
	MyRunnable runnable = new MyRunnable();
	Thread th = new Thread(runnable);
	Myrunnable1 myrunnable1 = new Myrunnable1();
	Thread th1 = new Thread(myrunnable1);
	MyRunnable2 myrunnable2 = new MyRunnable2();
	Thread th2 = new Thread(myrunnable2);
	Myrunnable3 myrunnable3 = new Myrunnable3();
	Thread th3 = new Thread(myrunnable3);
	JPanel panel;
	Keylistener keylistener;
	
	public void showGameFram(){
		JFrame f = new JFrame();
		f.setTitle("飞机大战");
		f.setSize(600, 1000);
		f.setLayout(null);
		f.setResizable(false);
		f.setLocationRelativeTo(null);
		
		

		panel = new JPanel();
		panel.setLayout(null);
		panel.setSize(800,1000);
		f.add(panel);
		
		//ImageIcon imageicon = new ImageIcon("/Users/niwenxian/study/java/plane_battle/src/main/resources/0-0.png");
		ImageIcon imageicon = new ImageIcon(GameFrame.class.getResource("/0-0.png"));
		JLabel label = new JLabel(imageicon);
		label.setSize(600, 1000);
		label.setLocation(0, 0);
		panel.add(label);

		
		keylistener = new Keylistener();
		panel.addKeyListener(keylistener);
		
		//对象同步
		runnable.hp = keylistener.hp;
		runnable.booms = booms;
		runnable.emenies = emenies;
		runnable.herobooms = keylistener.herobooms;
		myrunnable1.ex = runnable.ex;
		myrunnable2.booms = runnable.booms;
		myrunnable2.emenies = runnable.emenies;
		myrunnable3.emenies = emenies;
		
		

		
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Graphics g = panel.getGraphics();
		runnable.g = g;
		myrunnable1.g = g;
		
		ScoreShow sshow = new ScoreShow(g);
		sshow.g = g;
		runnable.sshow  = sshow;
		
		
		
		//启动线程
		//添加开始界面后，将线程的启动部分移动到了开始界面中

		/*
		th.start();
		th1.start();
		th3.start();
		th2.start();

		panel.requestFocus();
		*/
		
	}

	public static void main(String[] args){
		
		GameFrame g = new GameFrame();
		g.showGameFram();
		StartView st = new StartView();
		st.framepanel = g.panel;
		st.listener = g.keylistener;
		st.th = g.th;
		st.th1 = g.th1;
		st.th2 = g.th2;
		st.th3 = g.th3;
		st.showUI();
	}
}
